package ThreadPoolDemo.bilibiliThread;

import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestDemoTwo {

	private static Map<String, ExecutorService> map = new HashMap<String, ExecutorService>();

	public static void main(String[] args) {
		Timer timer = new Timer();
		for (int i = 0; i < 3; i++) {
			ExecutorService newFixedThreadPool = Executors
					.newSingleThreadExecutor();
			map.put(i + "", newFixedThreadPool);
			newFixedThreadPool.execute(new Runnable() {

				@Override
				public void run() {
					try {
						System.out.println(Thread.currentThread().getName()
								+ "开始");
						Thread.sleep((long) (Math.random() * 10000));
						System.out.println(Thread.currentThread().getName()
								+ "结束");
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			});
			timer.schedule(new TimerTask() {

				@Override
				public void run() {
					System.out.println(newFixedThreadPool.isTerminated());

				}
			}, 1, 1000);

		}

	}
}
